﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.GateUI {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import flash.filters.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.border.*;
    import Classes.gates.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class GateDialog extends GenericDialog {

        public static const TITLE_FONT:ASFont = ASwingHelper.getBoldFont(28);
        public static const TEXT_FONT:ASFont = ASwingHelper.getBoldFont(12);
        public static const BUTTON_FONT:ASFont = ASwingHelper.getBoldFont(12);
        public static const TEXT_COLOR:uint = 489375;
        public static const TITLE_COLOR:uint = 0xFFFFFF;
        public static const GLOW_FILTER:GlowFilter = new GlowFilter(489375, 1, 5, 5, 4, 2);

        public static var assets:Dictionary;

        protected var m_list:Component;
        protected var m_listData:Array;
        private var m_cellFactory:GridListCellFactory;
        private var m_subtext:String;
        private var m_listHeight:int;
        private var m_listWidth:int;
        protected var m_canBeFinished:Boolean;
        protected var m_finishButton:CustomButton;
        protected var m_buyAllButton:CustomButton;
        protected var m_buttonPanel:Container;
        protected var m_headerPanel:Component;
        protected var m_listPanel:Component;
        protected var m_finishCheckCB:Function;
        protected var m_finishCB:Function;
        private var m_buyAllCB:Function;
        private var m_columns:int;
        protected var m_gateType:String;

        public function GateDialog(_arg1:Array, _arg2:GridListCellFactory, _arg3:String, _arg4:String, _arg5:Function, _arg6:Function, _arg7:Function, _arg8:int=3, _arg9:Number=562, _arg10:Number=205, _arg11:Boolean=true){
            m_jpanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 1, SoftBoxLayout.LEFT));
            m_title = _arg3;
            this.m_subtext = _arg4;
            this.m_listData = _arg1;
            this.m_cellFactory = _arg2;
            this.m_listWidth = _arg9;
            this.m_listHeight = _arg10;
            this.m_finishCheckCB = _arg5;
            this.m_finishCB = _arg6;
            this.m_canBeFinished = this.m_finishCheckCB();
            this.m_buyAllCB = _arg7;
            this.m_columns = _arg8;
            super("", _arg3, 0, null, _arg3, "", _arg11);
        }
        override protected function loadAssets():void{
            Global.delayedAssets.get(DelayedAssetLoader.BUILDABLE_ASSETS, makeAssets);
        }
        override protected function onAssetsLoaded(_arg1:Event=null):void{
            assets = new Dictionary(true);
            assets["buildables_bg"] = m_comObject.buildables_bg;
            assets["buildables_check"] = m_comObject.buildables_check;
            assets["buildables_item"] = m_comObject.buildables_item;
            assets["buildables_wishlistIcon"] = m_comObject.buildables_wishlistIcon;
            this.createDialog();
        }
        protected function createHeaderPanel():Component{
            var _local1:Container = new JPanel(new BorderLayout());
            var _local2:Component = this.createTitlePanel();
            var _local3:AbstractButton = this.createCloseButton();
            var _local4:JPanel = ASwingHelper.makeCloseButtonOffset();
            _local1.append(_local2, BorderLayout.CENTER);
            _local1.append(_local3, BorderLayout.EAST);
            _local1.append(_local4, BorderLayout.WEST);
            return (_local1);
        }
        protected function createTitlePanel():Component{
            var _local1:Container = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local2:Component = this.createTitle();
            _local1.append(_local2);
            return (_local1);
        }
        protected function createTitle():Component{
            var _local1:JTextField = ASwingHelper.makeTextField(m_title, EmbeddedArt.TITLE_FONT, 30, EmbeddedArt.titleColor);
            _local1.filters = EmbeddedArt.titleFilters;
            var _local2:TextFormat = new TextFormat();
            _local2.size = 36;
            TextFieldUtil.formatSmallCaps(_local1.getTextField(), _local2);
            _local1.getTextField().height = 45;
            return (_local1);
        }
        protected function createCloseButton():AbstractButton{
            var _local1:JButton = ASwingHelper.makeMarketCloseButton();
            ASwingHelper.setEasyBorder(_local1, 0, 0, 17, 8);
            _local1.addActionListener(this.onCancelX);
            return (_local1);
        }
        protected function createButtonPanel():Container{
            var _local1:Container = new JPanel(new SoftBoxLayout(SoftBoxLayout.X_AXIS, 10, SoftBoxLayout.CENTER));
            var _local2:AssetIcon = new AssetIcon((new EmbeddedArt.icon_cash_big() as DisplayObject));
            this.m_buyAllButton = new CustomButton(ZLoc.t("Dialogs", "BuyAllButtonLabel"), _local2, "BigCashButtonUI");
            this.m_buyAllButton.addActionListener(this.onBuyAll, 0, true);
            var _local3:String = ((this.m_gateType)==AbstractGate.PRE_BUILD_GATE) ? ZLoc.t("Dialogs", "StartBuilding") : ZLoc.t("Dialogs", "FinishBuilding");
            this.m_finishButton = new CustomButton(_local3, null, "GreenButtonUI");
            this.m_finishButton.setEnabled(this.m_canBeFinished);
            this.m_finishButton.addActionListener(this.onFinishClick, 0, true);
            var _local4:EmptyBorder = new EmptyBorder(null, new Insets(0, 0, 0, 0));
            _local1.appendAll(this.m_buyAllButton, this.m_finishButton);
            _local1.setBorder(_local4);
            return (_local1);
        }
        protected function createListPanel():Component{
            var _local1:Container = new JPanel(new SoftBoxLayout(SoftBoxLayout.X_AXIS, 0, SoftBoxLayout.CENTER));
            this.m_list = this.createList();
            ASwingHelper.setEasyBorder(this.m_list, 0, -4);
            _local1.append(this.m_list);
            return (_local1);
        }
        protected function createList():Component{
            var _local1:int = (((this.m_listData.length - 1) / this.m_columns) + 1);
            var _local2:ASwingScrollingList = new ASwingScrollingList(this.m_listData, this.m_cellFactory, ASwingScrollingList.SCROLL_HORIZONTAL, this.m_columns, _local1, (this.m_listWidth * (Math.min(this.m_columns, this.m_listData.length) / this.m_columns)), (this.m_listHeight * _local1), false);
            _local2.scrollHPolicy = JScrollPane.SCROLLBAR_NEVER;
            _local2.scrollVPolicy = JScrollPane.SCROLLBAR_NEVER;
            return (_local2);
        }
        protected function layoutComponents():void{
            var _local1:DisplayObject = (new (assets["buildables_bg"])() as DisplayObject);
            m_jpanel.setBackgroundDecorator(new AssetBackground(_local1));
            m_jpanel.append(this.m_headerPanel);
            m_jpanel.append(this.m_listPanel);
            m_jpanel.append(ASwingHelper.verticalStrut(5));
            m_jpanel.append(this.m_buttonPanel);
        }
        protected function createDialog():void{
            this.m_headerPanel = this.createHeaderPanel();
            this.m_buttonPanel = this.createButtonPanel();
            this.m_listPanel = this.createListPanel();
            this.layoutComponents();
            finalizeAndShow();
        }
        protected function onCancelX(_arg1:Event):void{
            countDialogAction("X");
            this.closeMe(_arg1);
        }
        override protected function closeMe(_arg1:Event):void{
            super.closeMe(_arg1);
        }
        protected function onFinishClick(_arg1:Event):void{
            var _local2:Event;
            if (this.m_canBeFinished == false){
                countDialogAction("FINISH");
                return;
            };
            this.closeMe(_local2);
            this.m_finishCB();
        }
        protected function onBuyAll(_arg1:Event):void{
            countDialogAction("BUY ALL");
            this.m_buyAllCB();
        }
        public function activateFinishButton():void{
            this.m_canBeFinished = true;
            this.m_buttonPanel.remove(this.m_finishButton);
            this.m_finishButton = null;
            var _local1:String = ((this.m_gateType)==AbstractGate.PRE_BUILD_GATE) ? ZLoc.t("Dialogs", "StartBuilding") : ZLoc.t("Dialogs", "FinishBuilding");
            this.m_finishButton = new CustomButton(_local1, null, "GreenButtonUI");
            this.m_finishButton.setEnabled(this.m_canBeFinished);
            this.m_finishButton.addActionListener(this.onFinishClick, 0, true);
            this.m_buttonPanel.append(this.m_finishButton);
            ASwingHelper.prepare(this.m_buttonPanel);
        }
        public function setFinishButtonText(_arg1:String):void{
            this.m_buttonPanel.remove(this.m_finishButton);
            this.m_finishButton = null;
            this.m_finishButton = new CustomButton(_arg1, null, "GreenButtonUI");
            this.m_finishButton.setEnabled(this.m_canBeFinished);
            this.m_finishButton.addActionListener(this.onFinishClick, 0, true);
            this.m_buttonPanel.append(this.m_finishButton);
            ASwingHelper.prepare(this.m_buttonPanel);
        }
        public function setGateType(_arg1:String):void{
            this.m_gateType = _arg1;
            var _local2:String = ((this.m_gateType)==AbstractGate.PRE_BUILD_GATE) ? ZLoc.t("Dialogs", "StartBuilding") : ZLoc.t("Dialogs", "FinishBuilding");
            this.setFinishButtonText(_local2);
        }

    }
}//package Display.GateUI 
